package org.hzero.exam.api.controller.v1;

import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.*;
import org.hzero.core.base.BaseController;
import org.hzero.core.util.Results;
import org.hzero.exam.config.SwaggerTags;
import org.hzero.exam.domain.entity.HodrItem;
import org.hzero.exam.domain.repository.HodrItemRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 马旭阳
 * @date2019/8/5
 */
@Api(tags = SwaggerTags.ITEM)
@RestController("itemController.v1")
@RequestMapping("/v1/{organizationId}/items")
public class HodrItemController extends BaseController {
    @Autowired
    private HodrItemRepository itemRepository;
    @Permission(level = ResourceLevel.SITE)
    @ApiOperation(value = "根据物料编号或物料描述分页查询物料信息")
    @GetMapping
    public ResponseEntity<Page<HodrItem>> selectByCustomerNumberAndName(@PathVariable Long organizationId,
                                                                        @ApiParam(value = "物料编号")  String itemCode,
                                                                        @ApiParam(value = "物料名称")  String itemDescription,
                                                                        PageRequest pageRequest){
        return Results.success(PageHelper.doPage(pageRequest,()->itemRepository.selectByItemCodeAndDescription(itemCode,itemDescription)));
    }
}
